package com.zx.controller;

import com.zx.common.ResponseCode;
import com.zx.entity.User;
import com.zx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("/back")
public class BackController {
    @Autowired
    private UserService userService;
    //后台访问
    @GetMapping("/index")
    public ModelAndView backstage(HttpSession session,
                                  Map<String,Object> map){
        String username = (String) session.getAttribute("loginUser");
        User user = userService.findUserInfoByUsername(username);
        if(user.getRole().equals(0)){
            map.put("username",username);
            return new ModelAndView("home/back");
        }
        map.put("msg", ResponseCode.ROLE_ERROR.getDesc());
        map.put("user",user);
        map.put("url","/foodshare/main/index");
        return new ModelAndView("common/error");
    }
}
